//
// Copyright (c) 2009 All Right Reserved
//
// Stephen Toub
// stoub@microsoft.com
// 2009-01-01
// Contains ...
using System;
using System.Globalization;
using System.IO;
using System.Text;
using LargoCommon.Music;
namespace LargoCommon.Midi
{
/// MIDI event to modify a note according to the aftertouch of a key.
[Serializable]
public sealed class VoiceAftertouch : VoiceAbstractNote {
#region Fields
/// The category status byte for Aftertouch messages.
private const byte CategoryStatusByte = 0xA;
/// The pressure of the note (0x0 to 0x7F).
private byte pressure;
#endregion
#region Constructors
/// Initializes a new instance of the VoiceAftertouch class.
/// The amount of time before this event.
/// The channel (0x0 through 0xF) for this voice event.
/// The MIDI note to modify (0x0 to 0x7F).
/// The pressure of the note (0x0 to 0x7F).
public VoiceAftertouch(long deltaTime, MidiChannel channel, byte note, byte givenPressure) :
base(deltaTime, CategoryStatusByte, channel, note) {
this.Pressure = givenPressure;
}
#endregion
#region Properties
/// Gets The second parameter as sent in the MIDI message.
/// General musical property.
public override byte Parameter2 => this.pressure;
/// Gets or sets the pressure of the note (0x0 to 0x7F).
/// General musical property.
private byte Pressure {
get => this.pressure;
set {
if (value > 127) {
this.pressure = 127;
return;
//// throw new ArgumentOutOfRangeException("value", value, "The pressure must be in the range from 0 to 127.");
}
this.pressure = value;
}
}
#endregion
#region To String
/// Generate a string representation of the event.
/// A string representation of the event.
public override string ToString() {
var sb = new StringBuilder();
sb.Append(base.ToString());
sb.Append("\t");
sb.Append("0x");
sb.Append(this.Pressure.ToString("X2", CultureInfo.CurrentCulture.NumberFormat));
return sb.ToString();
}
#endregion
#region Methods
/// Write the event to the output stream.
/// The stream to which the event should be written.
public override void Write(Stream outputStream) {
//// Contract.Requires(outputStream != null);
if (outputStream == null) {
return;
}
//// Write out the base event information
base.Write(outputStream);
//// Write out the data
outputStream.WriteByte(this.pressure);
}
#endregion
}
}